import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:oss_upload/oss_upload.dart';
import 'package:practice/constants/constants.dart';
import 'package:practice/manager/user_manager.dart';
import 'package:practice/toast_utils.dart';
import 'package:practice/ui/main/main_logic.dart';
import 'package:practice/widget/custom_app_bar.dart';

class MainPage extends StatelessWidget {
  final MainLogic logic = Get.put(MainLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppbar(title: Text('云实践主界面')),
      body: Column(
        children: [
          TextButton(
              onPressed: upload,
              child: Text("上传文件测试")),
        ],
      ),
    );
  }

  upload() async {
    FilePickerResult? result = await FilePicker.platform.pickFiles();
    if (result == null) {
      return;
    }
    var uploadFile = await OSSUpload.uploadFile(
        result.files.single.path!,
        UserManager.user.id!,
        UserManager.organ.institutionId!,
        UserManager.organ.privateKey!,
        isDebug: Constants.debug);
    if (uploadFile != null) {
      print(uploadFile);
      ToastUtils.showToast(msg: uploadFile.toString());
    }
  }
}
